package org.meb.conquest.db.helpers;

import java.util.HashSet;
import java.util.Set;

import org.apache.commons.collections4.Predicate;
import org.meb.conquest.db.model.CardBase;
import org.meb.conquest.db.model.DomainBase;

public class PredicateUtils {

	public static Predicate<CardBase> createCardSet(String... techNames) {
		final Set<String> techNamesSet = new HashSet<>();
		for (String techName : techNames) {
			techNamesSet.add(techName);
		}

		Predicate<CardBase> keepPredicate = new Predicate<CardBase>() {

			@Override
			public boolean evaluate(CardBase cb) {
				return techNamesSet.contains(cb.getCardSetBase().getTechName());
			}

		};

		return keepPredicate;
	}
	
	public static Predicate<CardBase> createCardSet(Integer... sequences) {
		final Set<Integer> sequencesSet = new HashSet<>();
		for (Integer sequence : sequences) {
			sequencesSet.add(sequence);
		}

		Predicate<CardBase> keepPredicate = new Predicate<CardBase>() {

			@Override
			public boolean evaluate(CardBase cb) {
				return sequencesSet.contains(cb.getCardSetBase().getSequence());
			}

		};

		return keepPredicate;
	}

	public static Predicate<DomainBase> createDomain(String... domains) {
		final Set<String> domainsSet = new HashSet<>();
		for (String domain : domains) {
			domainsSet.add(domain);
		}

		Predicate<DomainBase> keepPredicate = new Predicate<DomainBase>() {

			@Override
			public boolean evaluate(DomainBase cb) {
				return domainsSet.contains(cb.getDomain());
			}

		};

		return keepPredicate;
	}
}
